#include <cstdio>
#include <algorithm>

int const maxn = 101;
int da[maxn][maxn];

int main()
{
#ifndef __SKT__
    freopen("lucky.in", "r", stdin);
    freopen("lucky.out", "w", stdout);
#endif

    int r, c;
    std::scanf("%d %d", &r, &c);
    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= c; j++) std::scanf("%d", &da[i][j]);

    int ans = 0;
    for (int i = 1; i <= r; i++) {
        int max = 0;
        for (int j = 1; j <= c; j++) {
            if (da[i][j] > max) ans++;
            max = std::max(max, da[i][j]);
        }
    }
    for (int i = 1; i <= r; i++) {
        int max = 0;
        for (int j = c; j >= 1; j--) {
            if (da[i][j] > max) ans++;
            max = std::max(max, da[i][j]);
        }
    }

    for (int j = 1; j <= c; j++) {
        int max = 0;
        for (int i = 1; i <= r; i++) {
            if (da[i][j] > max) ans++;
            max = std::max(max, da[i][j]);
        }
    }
    for (int j = 1; j <= c; j++) {
        int max = 0;
        for (int i = r; i >= 1; i--) {
            if (da[i][j] > max) ans++;
            max = std::max(max, da[i][j]);
        }
    }

    std::printf("%d\n", ans);
}
